package com.ficus.road.maintain.authority.config;

import com.ficus.road.maintain.authority.utils.SecurityUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xiawen yang
 * @date 2021/9/1 上午11:26
 */
@Service(value = "rm")
public class RMPermissionConfig {

//    @Autowired
//    private AuthorityConfig authorityConfig;

    public Boolean check(String... permissions) {

//        List<String> permitUrlList = authorityConfig.getPermitUrlList();
//        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//        String requestURI = request.getRequestURI();
        //获取当前用户的所有权限
        List<String> rmPermissions = SecurityUtils.getCurrentUser().getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
        return rmPermissions.contains("ADMIN") || Arrays.stream(permissions).anyMatch(rmPermissions::contains);
    }
}
